package drds.server.memory.unsafe.memory.mm;

import drds.server.memory.unsafe.utils.PropertyConfig;

/**
 * Created by zagnix on 2016/6/7.
 */
public class ResultMergeMemoryManager extends MemoryManager {

	private long maxOnHeapExecutionMemory;
	private int numCores;
	private PropertyConfig conf;

	public ResultMergeMemoryManager(PropertyConfig conf, int numCores, long onHeapExecutionMemory) {
		super(conf, numCores, onHeapExecutionMemory);
		this.conf = conf;
		this.numCores = numCores;
		this.maxOnHeapExecutionMemory = onHeapExecutionMemory;
	}

	@Override
	protected synchronized long acquireExecutionMemory(long numBytes, long taskAttemptId, MemoryMode memoryMode) throws InterruptedException {
		switch (memoryMode) {
		case ON_HEAP:
			return onHeapExecutionMemoryPool.acquireMemory(numBytes, taskAttemptId);
		case OFF_HEAP:
			return offHeapExecutionMemoryPool.acquireMemory(numBytes, taskAttemptId);
		}
		return 0L;
	}

}
